import yaml
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

#定义获取cookie函数
def getcookie():
    # 复用已有游览器
    # cmd：输入chrome --remote-debugging-port=9222
    option = Options()
    option.debugger_address = '127.0.0.1:9222'
    driver = webdriver.Chrome(options=option)
    # 获取cookie并保存至Cookie.yamal
    cookies = driver.get_cookies()
    with open("Cookie.yaml",'w') as f:
        yaml.dump(data=cookies,stream=f)

if __name__ == '__main__':
    getcookie()